package com.lin.sys.service.impls;



import org.apache.dubbo.config.annotation.Service;
import com.lin.common.service.impl.BaseService;
import com.lin.sys.dao.SysDeptMapper;
import com.lin.sys.entity.SysDept;
import dto.SysDeptDto;
import org.springframework.beans.factory.annotation.Autowired;
import service.DeptService;
import util.BeanUtils;
import util.ResponseVo;
import java.util.Date;
import java.util.List;

@Service
public class DeptServiceImpl extends BaseService<SysDept> implements DeptService {
    @Autowired
    private SysDeptMapper sysDeptMapper;

    @Override
    public ResponseVo addDept(SysDeptDto dept) {
        SysDept sysDept=new SysDept();
        dept.setCreateTime(new Date());
        BeanUtils.copyProperties(dept,sysDept);
        this.save(sysDept);
        return ResponseVo.ok("添加成功");
    }
    @Override
    public List<SysDeptDto> getDeptList() {
        List<SysDept> depts = this.selectAll();

        return BeanUtils.copyList(depts,SysDeptDto.class);
    }



    @Override
    public ResponseVo updateDept(SysDeptDto dept) {
        SysDept sysDept=new SysDept();
        BeanUtils.copyProperties(dept,sysDept);
        this.updateNotNull(sysDept);
        return ResponseVo.ok("更新成功");
    }

    @Override
    public ResponseVo deleteDept(Long id) {
        this.delete(id);
        // 删除后连带子部门一起删除
        sysDeptMapper.deleteChild(id);
        return ResponseVo.ok("删除成功");
    }
}
